package com.yu.blog.constant;

import jakarta.annotation.PostConstruct;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

@Data
@Component
@ConfigurationProperties(prefix = "constant")
public class ConstantData {

    /**
     * LoginUrl
     */
    public static String LoginUrl;

    @Value("${url.login:/api/auth/login}")
    public void setLoginUrl(String loginUrl) {
        LoginUrl = loginUrl;
    }

    /**
     * LogoutUrl
     */
    public static String LogoutUrl;

    @Value("${url.logout:/api/auth/logout}")
    public void setLogoutUrl(String logoutUrl) {
        LogoutUrl = logoutUrl;
    }

    /**
     * swagger白名单
     */
    public static List<String> WhiteList = List.of("/favicon.ico", "/webjars/**", "/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html", "/doc.html");

    /**
     * JwtAuthenticationFilter放行swagger路径
     */
    public static List<String> SwaggerUrl = List.of("/v3/api-docs/swagger-config", "/v3/api-docs", "/swagger");

    /**
     * 静态资源
     */
    public static List<String> SourceList = List.of("html", "css", "png", "js", "ico");

    /**
     * 跨域路径
     */
    public static String AllowedOriginPattern;

    @Value("${allowedOrigin.pattern:http://localhost:**}")
    public void setAllowedOriginPattern(String allowedOriginPattern) {
        AllowedOriginPattern = allowedOriginPattern;
    }

    /**
     * 自定义白名单
     */
    public static List<String> MyWhiteLists;
    private List<String> WhiteLists;

    @PostConstruct
    public void init() {
        ConstantData.MyWhiteLists = Objects.requireNonNullElseGet(this.WhiteLists, () -> List.of("/test/**"));
    }

}
